package com.maple.design.single;

/**
 * <p>单例</p>
 * 双重校验锁法（线程安全）
 *
 * @author maple
 * @since 2023/3/28
 */
public class Singleton {

    private volatile static Singleton singleton;

    private Singleton() {
        System.out.println("Singleton创建完成。");
    }

    private static synchronized Singleton getSingletonInstance() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {
        getSingletonInstance();
    }
}
